package com.yanqu.road.entity.activity.huashigang;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.DataStatus;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author wpj
 * @Date 2020/10/11
 */
@FieldTypeAnnotation(tableName = "t_u_huashigang_user_floor")
public class HuaShiGangUserFloor extends DataObject {
    @FieldTypeAnnotation(select = true, update = true)
    int activityId;
    @FieldTypeAnnotation(select = true, update = true)
    long userId;
    @FieldTypeAnnotation(desc = "层数")
    int floor;
    @FieldTypeAnnotation(desc = "单层数据")
    List<HuaShiGangFloorCellData> cellDataList = new ArrayList<>();
    @FieldTypeAnnotation(desc = "当前礼包id")
    int currentMall;
    @FieldTypeAnnotation(desc = "下一个礼包id")
    int nextMall;
    @FieldTypeAnnotation(desc = "礼包存量")
    Map<Integer, Long> mallMap = new ConcurrentHashMap<>();
    @FieldTypeAnnotation(desc = "是否获得过大奖,0否1是")
    int gotBigReward;
    //触发礼包次数
    private Map<Integer,Integer> mallTimesMap = new ConcurrentHashMap<>();


    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }

    }
    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }

    }
    public void setFloor(int floor) {
        if (this.floor != floor) {
            this.floor = floor;
            setOp(DataStatus.Update);
        }

    }

    public int getActivityId() {
        return activityId;
    }

    public long getUserId() {
        return userId;
    }

    public int getFloor() {
        return floor;
    }

    public List<HuaShiGangFloorCellData> getCellDataList() {
        return cellDataList;
    }

    public void setCellDataList(List<HuaShiGangFloorCellData> cellDataList) {
        this.cellDataList = cellDataList;
    }

    public int getCurrentMall() {
        return currentMall;
    }

    public void setCurrentMall(int currentMall) {
        if (this.currentMall != currentMall) {
            this.currentMall = currentMall;
            setUpdateOption();
        }
    }

    public int getNextMall() {
        return nextMall;
    }

    public void setNextMall(int nextMall) {
        if (this.nextMall != nextMall) {
            this.nextMall = nextMall;
            setUpdateOption();
        }
    }

    public Map<Integer, Long> getMallMap() {
        return mallMap;
    }

    public String getMallMapJsonStr() {
        return JSON.toJSONString(mallMap);
    }

    public long getMallTime(int mallId){
        if(mallMap.containsKey(mallId)){
            return mallMap.get(mallId);
        }
        return 0;
    }

    public void setMallTime(int mallId, long time){
        mallMap.put(mallId, time);
        setUpdateOption();
    }

    public void removeMall(int mallId){
        mallMap.remove(mallId);
        setUpdateOption();
    }

    public void setMallMap(Map<Integer, Long> mallMap) {
        this.mallMap = mallMap;
        setUpdateOption();
    }

    public int getGotBigReward() {
        return gotBigReward;
    }

    public void setGotBigReward(int gotBigReward) {
        if (this.gotBigReward != gotBigReward){
            this.gotBigReward = gotBigReward;
            setUpdateOption();
        }
    }

    public Map<Integer, Integer> getMallTimesMap() {
        return mallTimesMap;
    }

    public String getMallTimesMapJsonStr() {
        return JSON.toJSONString(mallTimesMap);
    }

    public void setMallTimesMap(Map<Integer, Integer> mallTimesMap) {
        this.mallTimesMap = mallTimesMap;
        setUpdateOption();
    }

    public int getMallTimes(int mallId){
        if(mallTimesMap.containsKey(mallId)){
            return mallTimesMap.get(mallId);
        }
        return 0;
    }

    public void addMallTimes(int mallId, int times){
        int totalTimes = getMallTimes(mallId);
        totalTimes += times;
        mallTimesMap.put(mallId, totalTimes);
        setUpdateOption();
    }

    public void clearMallTimes(int mallId){
        mallTimesMap.remove(mallId);
        setUpdateOption();
    }

    public void reduceMallTimes(int mallId, int times){
        int totalTimes = getMallTimes(mallId);
        totalTimes -= times;
        if(totalTimes < 0){
            totalTimes = 0;
        }
        mallTimesMap.put(mallId, totalTimes);
        setUpdateOption();
    }
}
